<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>减少声明及语句数</title>
</head>
<body>
  <!-- 求面积 -->
  <div id="box" style="width: 100px; height: 100px"></div>
  <script>
    var box = document.getElementById('box')

    var test = ele => {
      let w = ele.offsetWidth
      let h = ele.offsetHeight
      return w * h
    }
    console.log(test(box))

    // 优化后
    var test2 = ele => {
      return ele.offsetWidth * ele.offsetHeight
    }
    console.log(test2(box))

    /* 分割线 */
    var test3 = () => {
      var name = 'name'
      var age = 12
      var slogan = 'hello world'
      return name + age + slogan
    }
    console.log(test3())


    var test4 = () => {
      var name = 'name',
          age = 12,
          slogan = 'hello world'
      return name + age + slogan
    }
    console.log(test4())
  </script>
</body>
</html>